package com.fcmeditech.AsianSexyGirls.adwhirl;

import android.app.Activity;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;

import com.mobclix.android.sdk.MobclixAdView;
import com.mobclix.android.sdk.MobclixAdViewListener;
import com.mobclix.android.sdk.MobclixMMABannerXLAdView;

public class AdwhirlCustomEvents implements CustomAdwhirlInterface {

	private static MobclixListener mclistener;
	private static MobclixMMABannerXLAdView adview;
	private static boolean MobclixOn;
	private Activity mContext;

	public AdwhirlCustomEvents(Activity mContext) {
		this.mContext = mContext;
		MobclixOn = false;
	}

	@Override
	public void MobclixEvent() {
		Log.i("MobclixEvent", "Request MobClix Ad");
		if(!MobclixOn) {
			mclistener = new MobclixListener();
			adview = new MobclixMMABannerXLAdView(mContext);
			MobclixOn = true;
		}
		adview.addMobclixAdViewListener(mclistener);
		adview.getAd();
	}

	public class MobclixListener implements MobclixAdViewListener {

		@Override
		public void onFailedLoad(MobclixAdView adview, int errorcode) {
			Log.i("MobclixEvent", "Mobclix Fail");
			try{
				adview.removeMobclixAdViewListener(mclistener);
				AdManager.adWhirlLayout.rollover();
			} catch(RuntimeException i){}
		}

		@Override
		public void onSuccessfulLoad(MobclixAdView adview) {
			Log.i("MobclixEvent", "Mobclix Success");
			try {
				adview.removeMobclixAdViewListener(mclistener);
				adview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
				AdManager.adWhirlLayout.pushSubView(adview);
				AdManager.adWhirlLayout.adWhirlManager.resetRollover();
				AdManager.adWhirlLayout.rotateThreadedDelayed();
			} catch (RuntimeException i){}
		}

		@Override
		public void onCustomAdTouchThrough(MobclixAdView arg0, String arg1) {}

		@Override
		public String keywords() {return null;}

		@Override
		public String query() {return null;}

		@Override
		public void onAdClick(MobclixAdView arg0) {}

		@Override
		public boolean onOpenAllocationLoad(MobclixAdView arg0, int arg1) {
			return false;
		}
	}

	@Override
	public void adWhirlGeneric() {}
}
